<?php


namespace app\admin\controller;


class Pay extends Base
{
    public function index()
    {
        $pays = model('Pay')->select();
        $viewData = [
            'pays' => $pays
        ];
        $this->assign($viewData);
        return view();
    }

    public function status()
    {
        //接收数据
        $data = [
            'id' => input('post.id'),
            //若status值为1，则变为0，反之为1
            'status' => input('post.status') ? 0 : 1
        ];
        //从数据库里查询出id赋值给adminInfo
        $payInfo = model('Pay')->find($data['id']);
        //将status更新为接收到的status
        $payInfo->pay_status = $data['status'];
        //更新
        $result = $payInfo->save();
        if ($result){
            $this->success('操作成功','admin/pay/index');
        }else{
            $this->error('操作失败');
        }
    }
}